/*package com.zhd.service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zhd.entity.WetherStationVO;

@Service
public class WetherService {
	private static final Logger logger = LoggerFactory.getLogger(WetherService.class);
	
	@Autowired
    private ObjectMapper objectMapper;
	@Autowired
    private RocketMQTemplate rocketMQTemplate;
	@Autowired
    @Qualifier("wsTemplate")
	private JdbcTemplate wsTemplate;
	
	DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
	
	public void wetherSchedule() throws JsonProcessingException {
		LocalDateTime now = LocalDateTime.now().minusMinutes(10).withSecond(0);
		
		String sql = "select "
				+ "idm, idfac sn, [time], e1, e2, e3, e4, e5, e6, e7, e8, e9 "
				+ "from dCurrent "
				+ "where [time] >= ? "
				+ "order by idm desc";
		
		List<WetherStationVO> list = wsTemplate.query(sql, new BeanPropertyRowMapper<WetherStationVO>(WetherStationVO.class), dtf.format(now));
		if(list == null || list.size() == 0) {
			logger.info("当天{}气象站没有数据", LocalDate.now());
			return;
		}
		WetherStationVO vo = list.get(0);
		List<Map<String, Object>> data = Lists.newArrayList();
		
		Map<String, Object> dataMap = Maps.newHashMap();
		dataMap.put("id", "e1");
		dataMap.put("key", "e1");
		dataMap.put("val", vo.getE1());
		data.add(dataMap);
		
		dataMap = Maps.newHashMap();
		dataMap.put("id", "e2");
		dataMap.put("key", "e2");
		dataMap.put("val", vo.getE2());
		data.add(dataMap);
		
		dataMap = Maps.newHashMap();
		dataMap.put("id", "e3");
		dataMap.put("key", "e3");
		dataMap.put("val", vo.getE3());
		data.add(dataMap);
		
		dataMap = Maps.newHashMap();
		dataMap.put("id", "e4");
		dataMap.put("key", "e4");
		dataMap.put("val", vo.getE4());
		data.add(dataMap);
		
		dataMap = Maps.newHashMap();
		dataMap.put("id", "e5");
		dataMap.put("key", "e5");
		dataMap.put("val", vo.getE5());
		data.add(dataMap);
		
		dataMap = Maps.newHashMap();
		dataMap.put("id", "e6");
		dataMap.put("key", "e6");
		dataMap.put("val", vo.getE6());
		data.add(dataMap);
		
		dataMap = Maps.newHashMap();
		dataMap.put("id", "e7");
		dataMap.put("key", "e7");
		dataMap.put("val", vo.getE7());
		data.add(dataMap);
		
		dataMap = Maps.newHashMap();
		dataMap.put("id", "e8");
		dataMap.put("key", "e8");
		dataMap.put("val", vo.getE8());
		data.add(dataMap);
		
		dataMap = Maps.newHashMap();
		dataMap.put("id", "e9");
		dataMap.put("key", "e9");
		dataMap.put("val", vo.getE9());
		data.add(dataMap);
		
		// 组装采集器数据
		Map<String, Object> deviceMap = Maps.newHashMap();
		deviceMap.put("devId", vo.getSn());
		deviceMap.put("sn", vo.getSn());
		deviceMap.put("time", dtf.format(vo.getTime()));
		deviceMap.put("tenantId", "");
		deviceMap.put("tags", null);
		deviceMap.put("data", data);
		
		String message = objectMapper.writeValueAsString(deviceMap);
		rocketMQTemplate.asyncSend("iot-huacheng", MessageBuilder.withPayload(message).setHeader("KEYS", vo.getSn()).build(), new SendCallback() {
			@Override
		    public void onSuccess(SendResult result) {
		        if (result.getSendStatus() == SendStatus.SEND_OK) {
		        	logger.info("气象站数据转发成功={}", message);
		        }
		    }
		    @Override
		    public void onException(Throwable e) {
		    	logger.error("气象站数据转发失败={}", e.getMessage());
		    }
		});
	}
}*/